package com.milotnt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.milotnt.mapper.CommunityCommentMapper;
import com.milotnt.pojo.CommunityCommentEntity;
import com.milotnt.service.CommunityCommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@Transactional
public class CommunityCommentServiceImpl extends ServiceImpl<CommunityCommentMapper, CommunityCommentEntity> implements CommunityCommentService {

    @Autowired
    private CommunityCommentMapper communityCommentMapper;

    @Override
    public Boolean addComment(CommunityCommentEntity comment) {
        if (comment == null || comment.getMemberId() == null || comment.getContent() == null || comment.getContent().trim().isEmpty()){
            return false;
        }
        comment.setParentId(null);
        return communityCommentMapper.insertComment(comment);
    }

    @Override
    public List<CommunityCommentEntity> selectCommentsById(Long postId) {
        if (postId == null){
            return new ArrayList<>();
        }
        return communityCommentMapper.selectCommentsById(postId);
    }
}
